import java.util.Scanner;

public class demo15 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println(zz(a,b));
    }
    public static int zz(int a,int b){
        if(b == 0){
            return a;
        }
        int c = a % b;

        return zz(b,c);
    }

}
